<template>

  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>
    
    <vxe-table 
      v-loading="loading" 
      :data="AssetAuditConfigList" 
      @selection-change="handleSelectionChange"
      border
      stripe
    >
      <vxe-column 
        field="configName" 
        title="配置名称" 
        align="center" 
        :render-cell="renderConfigName"
      />
      <vxe-column 
        field="status" 
        title="状态" 
        align="center" 
        :render-cell="renderStatus"
      />
    </vxe-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>

</template>


<script>
import { list, getAssetAuditConfig, delAssetAuditConfig, addAssetAuditConfig, updateAssetAuditConfig, exportAssetAuditConfig } from "./api.js";


export default {

  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      AssetAuditConfigList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        configName: null,
        configDesc: null,
        configType: null,
        orderType: null,
        status: null,
        createUserId: null,
        updateUserId: null
      },
      // 表单参数
      form: {},
      columns: [
            { key: 1, label: "配置名称", visible:  true  },
            { key: 2, label: "配置描述", visible:  true  },
            { key: 3, label: "配置类型", visible:  true  },
            { key: 4, label: "请求类型", visible:  true  },
            { key: 5, label: "状态 0-未启用 1-启用", visible:  true  },
                        { key: 9, label: "CREATE_USER_ID", visible:  true  },
            { key: 10, label: "UPDATE_USER_ID", visible:  false  },
         ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      const {pageNum, pageSize} = this.queryParams;
      const query = {...this.queryParams, pageNum: undefined, pageSize: undefined};
      const pageReq = {page: pageNum - 1, size: pageSize};
      list(query, pageReq, this.configType).then(response => {
        const { content, totalElements } = response
        this.AssetAuditConfigList = content;
        this.total = totalElements;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        configName: null,
        configDesc: null,
        configType: null,
        orderType: null,
        status: 0,
        createTime: null,
        updateTime: null,
        createUserId: null,
        updateUserId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAssetAuditConfig(id).then(response => {
        this.form = response;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAssetAuditConfig(this.form).then(() => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAssetAuditConfig(this.form).then(() => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delAssetAuditConfig(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有【请填写功能名称】数据项？').then(() => {
        this.exportLoading = true;
        return exportAssetAuditConfig(queryParams);
      }).then(response => {
        this.$download.download(response);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>

<style scoped>
.vxe-table {
  flex: 1;  
  overflow: auto; 
}

.pagination-container {
  margin-top: 16px; 
}
</style>